<template>
	<view class="content">
		<view class="row-area b-b">
			<text class="tit">商品名称</text>
			<textarea v-model="goodsData.name"/>
		</view>
		<view class="row b-b">
			<text class="tit">单价</text>
			<input class="input" type="number" v-model="goodsData.retailPrice" placeholder="单价" placeholder-class="placeholder" />
		</view>
		<view class="row b-b">
			<text class="tit">原价</text>
			<input class="input" type="number" v-model="goodsData.counterPrice" placeholder="原价" placeholder-class="placeholder" />
		</view>
		<!-- <view class="row b-b">
			<text class="tit">折扣</text>
			<input class="input" type="number" v-model="goodsData.mobile" placeholder="折扣" placeholder-class="placeholder" />
		</view> -->
		<!-- <view class="row b-b">
			<text class="tit">库存</text>
			<input class="input" type="number" v-model="goodsData.mobile" placeholder="库存" placeholder-class="placeholder" />
		</view> -->
		<view class="row-area b-b">
			<text class="tit">商品简介</text>
			<textarea v-model="goodsData.brief"/>
		</view>
		<button class="add-btn" @click="confirm">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				reqUrl:"/app/gamch/add_goods",
				goodsData: {
					
				}
			}
		},
		onLoad(option){
			console.log("onLoad---------------",option);
			let title = '新增商品';
			if(option.type==='update'){
				title = '编辑商品';
				this.reqUrl = "/app/gamch/update_goods";
				
				// this.addressData = JSON.parse(option.data);
			}
			
			uni.setNavigationBarTitle({
				title
			})
		},
		methods: {
			//提交
			confirm(){
				let data = this.goodsData;
				if(!data.name){
					this.$api.msg('请填写商品名称');
					return;
				}
				if(!data.name){
					this.$api.msg('请填写商品单价');
					return;
				}
				
				this.$api.request(this.reqUrl,this.goodsData).then(res=>{
					uni.navigateBack();
				}
					
				);
				
				/* 
				if (that.manageType === 'edit') {
					that.$api.request('address', 'updateAddress', {
						...that.addressData,
						addressId : that.addressData.id
					}).then(res => {
						that.$api.prePage().refreshList(data, that.manageType);
						uni.navigateBack()
					})
				} else {
					that.$api.request('address', 'addAddress', that.addressData).then(res => {
						that.$api.prePage().refreshList(data, that.manageType);
						uni.navigateBack()
					})
				} */
				
				/* //this.$api.prePage()获取上一页实例，可直接调用上页所有数据和方法，在App.vue定义
				this.$api.prePage().refreshList(data, this.manageType);
				this.$api.msg(`地址${this.manageType=='edit' ? '修改': '添加'}成功`);
				setTimeout(()=>{
					uni.navigateBack()
				}, 800) */
			},
		}
	}
</script>

<style lang="scss">
	page{
		background: $page-color-base;
		padding-top: 16upx;
	}
	
	.row-area{
		display: flex;
		align-items: center;
		position: relative;
		padding:0 30upx;
		background: #fff;
		.tit{
			flex-shrink: 0;
			width: 160upx;
			font-size: 30upx;
			color: $font-color-dark;
		}
	}

	.row{
		display: flex;
		align-items: center;
		position: relative;
		padding:0 30upx;
		height: 110upx;
		background: #fff;
		
		.tit{
			flex-shrink: 0;
			width: 160upx;
			font-size: 30upx;
			color: $font-color-dark;
		}
		.input{
			flex: 1;
			font-size: 30upx;
			color: $font-color-dark;
		}
		.icon-shouhuodizhi{
			font-size: 36upx;
			color: $font-color-light;
		}
	}
	.default-row{
		margin-top: 16upx;
		.tit{
			flex: 1;
		}
		switch{
			transform: translateX(16upx) scale(.9);
		}
	}
	.add-btn{
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690upx;
		height: 80upx;
		margin: 60upx auto;
		font-size: $font-lg;
		color: #fff;
		background-color: $base-color;
		border-radius: 10upx;
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
	}
</style>
